﻿using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UMLSynthesizer.CSharpAnalyzer.Helpers;
using UMLSynthesizer.LangAnalyzer.Statements;

namespace UMLSynthesizer.CSharpAnalyzer.Statements
{
    class CSharpElseClause : CSharpStatementBase, IElseClause
    {
        #region Fields

        ElseClauseSyntax elseBlock;
        CSharpStatementBlockHelper blockHelper;

        #endregion

        #region Constructor

        public CSharpElseClause(ElseClauseSyntax elseBlock, IStatementBase parentStatement)
            : base(null, parentStatement, null, StatementKinds.Else)
        {
            this.elseBlock = elseBlock;
            blockHelper = new CSharpStatementBlockHelper(this,
                () =>
                {
                    if (elseBlock.Statement.CSharpKind() == SyntaxKind.Block)
                        return (elseBlock.Statement as BlockSyntax).Statements;
                    else
                        return new StatementSyntax[] { elseBlock.Statement };
                });
        }

        #endregion

        #region Properties

        public IEnumerable<IStatementBase> ContainedStatements { get { return blockHelper.ContainedStatements; } }

        #endregion
    }
}
